package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.entity.SleepTimeReply;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeSleepTime implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData)
    {
        // // *WT,866248050395985,V4,SLEEPTIME,172643,02:00,03:00,1,A,2250.2269,N,11391.6194,E,0.15,0,020621,FFFFDFFF
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[4];
        String startTime=split[5];//开始时间
        String endTime = split[6];//结束时间
        String flag = split[7];//功能的开关 0-关闭 1-开启
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];//日月年
        String deviceStatus = split[16];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        SleepTimeReply sleepTimeReply = new SleepTimeReply();
        sleepTimeReply.setFlag(Integer.parseInt(flag));
        sleepTimeReply.setStart(startTime);
        sleepTimeReply.setEnd(endTime);
        sleepTimeReply.setImei(imei);
        sleepTimeReply.setCommandNumber(commandNumber);
        sleepTimeReply.setDeviceDate(deviceDate);
        sleepTimeReply.setDeviceStatus(deviceStatus);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        sleepTimeReply.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_SET_SLEEP_TIME,false,"",sleepTimeReply);
    }
}
